<template>
  <div>
    <div class="allsearch">
      <section class="search-content">
        <el-row :gutter="4" type="flex" justify="start">
          <el-col :span="24">
            <el-select v-model="listQuery.onlineUserType" style="width:150px;">
              <el-option v-for="item in onlineUserType" :key="item.value" :value="item.value" :label="item.label" />
            </el-select>
            <el-input v-model="listQuery.userName" style="width:240px;" placeholder="用户名" @keyup.enter.native="handleFilter" />
            <el-button type="primary" size="medium" @click="handleFilter">搜索</el-button>
            <el-button size="medium" type="info" @click="clearParams">清空</el-button>
          </el-col>
        </el-row>
      </section>
    </div>
    <ul class="checknum">
      <li>共查询到 <span>{{ total }}</span> 位符合条件的在线用户（15分钟以内有活动）</li>
    </ul>

    <el-table :data="onLineUserList" border fit highlight-current-row style="width: 100%;margin-top:15px;">
      <el-table-column min-width="10%" align="center" label="用户名">
        <template slot-scope="scope">
          <span>{{ scope.row.userName }}</span>
        </template>
      </el-table-column>
      <el-table-column min-width="15%" align="center" label="用户来源">
        <template slot-scope="scope">
          <span>{{ scope.row.source }}</span>
        </template>
      </el-table-column>
      <el-table-column min-width="15%" align="center" label="客户端">
        <template slot-scope="scope">
          <span>{{ scope.row.ip }}</span>
        </template>
      </el-table-column>
      <el-table-column min-width="20%" align="center" label="是否在线">
        <template slot-scope="scope">
          <span>{{ scope.row.isLogin === 0 ? '否' : '是' }}</span>
        </template>
      </el-table-column>
      <el-table-column min-width="20%" align="center" label="最后活跃时间">
        <template slot-scope="scope">
          <span>{{ scope.row.activeTime }}</span>
        </template>
      </el-table-column>
      <el-table-column min-width="20%" align="center" label="离线时间">
        <template slot-scope="scope">
          <span>{{ scope.row.deadline }}</span>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getOnLineUserData" />
  </div>
</template>

<script>
import Pagination from '@/components/Pagination' // 分页组件
import { getEduxcloudUserOnLinePager } from '@/api/user/user' // 数据接口
import { getTenantId } from '@/utils/auth'
export default {
  components: { Pagination },
  data() {
    return {
      onLineUserList: null,
      total: 0,
      listLoading: true,
      listQuery: {
        onlineUserType: '',
        userName: '',
        page: 1,
        limit: 20,
        tenantId: getTenantId()
      },
      onlineUserType: [
        { label: '全部访客', value: '' },
        { label: '注册用户', value: 'regisUser' },
        { label: '游客', value: 'tourist' }
      ]
    }
  },
  created() { this.getOnLineUserData() },
  methods: {
    // 分页数据获取
    getOnLineUserData() {
      getEduxcloudUserOnLinePager(this.listQuery).then(response => {
        this.onLineUserList = response.data.items
        this.total = response.data.total
      })
    },
    // 数据检索
    handleFilter() {
      this.getOnLineUserData()
    },
    clearParams() {
      this.listQuery.nickName = ''
      this.listQuery.onlineUserType = ''
      this.getOnLineUserData()
    }
  }
}
</script>

<style lang="scss" scoped>
.allsearch {
  margin-top: 0;
  padding: 0;
  .search-content {
    width: 100%;
  }
}
.checknum {
  list-style: none;
  padding: 0 0 0 11px;
  margin: 14px 0 21px;
  height: 44px;
  line-height: 44px;
  box-sizing: border-box;
  background-color: #f8f8f8;
  li {
    float: left;
    display: block;
    margin-right: 20px;
    color: #72726f;
    span {
      color: rgb(15, 202, 62);
      font-weight: 600;
    }
  }
}
</style>
